﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections; 
using System.Threading; 

namespace WindowsFormsApplication1.FloorUIForms
{
    public partial class FloorUI5 : Form, FloorUI
    {
        string namingConvention;
        Elevator elevator;

        ArrayList allCommands;
        ArrayList firstFloorCommands;
        ArrayList secondFloorCommands;
        ArrayList thirdFloorCommands;
        ArrayList fourthFloorCommands;
        ArrayList fifthFloorCommands; 

        public FloorUI5(String floorNaming, Elevator e)
        {
            InitializeComponent();
            namingConvention = floorNaming;
            elevator = e;

            allCommands = new ArrayList();
            firstFloorCommands = new ArrayList();
            secondFloorCommands = new ArrayList();
            thirdFloorCommands = new ArrayList();
            fourthFloorCommands = new ArrayList();
            fifthFloorCommands = new ArrayList(); 

            // Sets the naming of floors to either US or UK
            setFloorNaming();

            // Sets the current floor border
            borderCurrentFloorofElevator(elevator.getCurrentFloor());

            // Restrict access to the floors below minimum
            setupMinimumFloor();
        }

        private void setupMinimumFloor()
        {
            if (elevator.getMinFloor() == 1)
            {
            }
            else if (elevator.getMinFloor() == 2)
            {
                upBttnFirst.Hide();
                downBttnSecond.Hide();
            }
            else if (elevator.getMinFloor() == 3)
            {
                upBttnFirst.Hide();
                downBttnSecond.Hide();
                upBttnSecond.Hide();
                downBttnThird.Hide();
            }
            else if (elevator.getMinFloor() == 4)
            {
                upBttnFirst.Hide();
                downBttnSecond.Hide();
                upBttnSecond.Hide();
                downBttnThird.Hide();
                upBttnThird.Hide();
                downBttnFourth.Hide(); 
            }
        }

        private void addNewCommand(String command)
        {
            if (allCommands.Contains(command))
            {
            }
            else
            {
                allCommands.Add(command);
            }
        }

        private void addNewFirstFloorCommand(String command)
        {
            if (firstFloorCommands.Contains(command))
            {
            }
            else
            {
                firstFloorCommands.Add(command);
            }
        }

        private void addSecondFloorCommand(String command)
        {
            if (secondFloorCommands.Contains(command))
            {
            }
            else
            {
                secondFloorCommands.Add(command);
            }
        }

        private void addThirdFloorCommand(String command)
        {
            if (thirdFloorCommands.Contains(command))
            {
            }
            else
            {
                thirdFloorCommands.Add(command);
            }
        }

        private void addFourthFloorCommand(String command)
        {
            if (fourthFloorCommands.Contains(command))
            {
            }
            else
            {
                fourthFloorCommands.Add(command); 
            }
        }

        private void addFifthFloorCommand(String command)
        {
            if (fifthFloorCommands.Contains(command))
            {
            }
            else
            {
                fifthFloorCommands.Add(command); 
            }
        }

        private void removeCommand(String list, String command)
        {
            if (list.Equals("allCommands"))
            {
                allCommands.Remove(command);
            }
            else if (list.Equals("firstFloorCommands"))
            {
                firstFloorCommands.Remove(command);
            }
            else if (list.Equals("secondFloorCommands"))
            {
                secondFloorCommands.Remove(command);
            }
            else if (list.Equals("thirdFloorCommands"))
            {
                thirdFloorCommands.Remove(command);
            }
            else if (list.Equals("fourthFloorCommands"))
            {
                fourthFloorCommands.Remove(command); 
            }
            else if (list.Equals("fifthFloorCommands"))
            {
                fifthFloorCommands.Remove(command); 
            }
        }

        private String getNextCommand()
        {
            if (allCommands.Count != 0)
            {
                return allCommands[0].ToString();
            }
            else
            {
                return "";
            }
        }

        private void setFloorNaming()
        {
            if (namingConvention.Equals("UK"))
            {
                firstFloorLbl.Text = "G";
                secondFloorLbl.Text = "1";
                thirdFloorLbl.Text = "2";
                fourthFloorLbl.Text = "3";
                fifthFloorLbl.Text = "4"; 
            }
            else if (namingConvention.Equals("US"))
            {
                firstFloorLbl.Text = "1";
                secondFloorLbl.Text = "2";
                thirdFloorLbl.Text = "3";
                fourthFloorLbl.Text = "4";
                fifthFloorLbl.Text = "5"; 
            }
        }

        private void borderCurrentFloorofElevator(int floorNumber)
        {
            if (floorNumber == 1)
            {
                firstFloorPanel.BorderStyle = BorderStyle.FixedSingle;
            }
            else if (floorNumber == 2)
            {
                secondFloorPanel.BorderStyle = BorderStyle.FixedSingle;
            }
            else if (floorNumber == 3)
            {
                thirdFloorPanel.BorderStyle = BorderStyle.FixedSingle;
            }
            else if (floorNumber == 4)
            {
                fourthFloorPanel.BorderStyle = BorderStyle.FixedSingle;
            }
            else if (floorNumber == 5)
            {
                fifthFloorPanel.BorderStyle = BorderStyle.FixedSingle; 
            }
        }

        public void lightUpBttn(String floorNumber)
        {
            if (floorNumber.Equals("firstup"))
            {
                upBttnFirst.Image = Properties.Resources.up_button_small_lit;
            }
            else if (floorNumber.Equals("secondup"))
            {
                upBttnSecond.Image = Properties.Resources.up_button_small_lit;
            }
            else if (floorNumber.Equals("thirdup"))
            {
                upBttnThird.Image = Properties.Resources.up_button_small_lit;
            }
            else if (floorNumber.Equals("fourthup"))
            {
                upBttnFourth.Image = Properties.Resources.up_button_small_lit;
            }
            else if (floorNumber.Equals("seconddown"))
            {
                downBttnSecond.Image = Properties.Resources.down_button_small_lit;
            }
            else if (floorNumber.Equals("thirddown"))
            {
                downBttnThird.Image = Properties.Resources.down_button_small_lit;
            }
            else if (floorNumber.Equals("fourthdown"))
            {
                downBttnFourth.Image = Properties.Resources.down_button_small_lit;
            }
            else if (floorNumber.Equals("fifthdown"))
            {
                downBttnFifth.Image = Properties.Resources.down_button_small_lit;
            }
        }

        public void lightOutBttn(String floorNumber)
        {
        }

        private void upBttnFirst_Click(object sender, EventArgs e)
        {
            allCommands.Add("up1");
            firstFloorCommands.Add("up1"); 
            //new UCC.UCCPressUpButton(this, "firstup").Run(); 
            upBttnFirst.Image = Properties.Resources.up_button_small_lit;
        }

        private void downBttnSecond_Click(object sender, EventArgs e)
        {
            allCommands.Add("down2");
            secondFloorCommands.Add("down2"); 
            //new UCC.UCCPressDownButton(this, "seconddown").Run(); 
            downBttnSecond.Image = Properties.Resources.down_button_small_lit;
        }

        private void upBttnSecond_Click(object sender, EventArgs e)
        {
            allCommands.Add("up2");
            secondFloorCommands.Add("up2"); 
            //new UCC.UCCPressUpButton(this, "secondup").Run(); 
            upBttnSecond.Image = Properties.Resources.up_button_small_lit;
        }

        private void downBttnThird_Click(object sender, EventArgs e)
        {
            allCommands.Add("down3");
            thirdFloorCommands.Add("down3"); 
            //new UCC.UCCPressDownButton(this, "thirddown").Run(); 
            downBttnThird.Image = Properties.Resources.down_button_small_lit;
        }

        private void upBttnThird_Click(object sender, EventArgs e)
        {
            allCommands.Add("up3");
            thirdFloorCommands.Add("up3"); 
            //new UCC.UCCPressUpButton(this, "thirdup").Run(); 
            upBttnThird.Image = Properties.Resources.up_button_small_lit;
        }

        private void downBttnFourth_Click(object sender, EventArgs e)
        {
            allCommands.Add("down4");
            fourthFloorCommands.Add("down4"); 
            //new UCC.UCCPressDownButton(this, "fourthdown").Run(); 
            downBttnFourth.Image = Properties.Resources.down_button_small_lit;
        }

        private void upBttnFourth_Click(object sender, EventArgs e)
        {
            allCommands.Add("up4");
            fourthFloorCommands.Add("up4"); 
            //new UCC.UCCPressUpButton(this, "fourthup").Run(); 
            upBttnFourth.Image = Properties.Resources.up_button_small_lit;
        }

        private void downBttnFifth_Click(object sender, EventArgs e)
        {
            allCommands.Add("down5");
            fifthFloorCommands.Add("down5"); 
            //new UCC.UCCPressDownButton(this, "fifthdown").Run(); 
            downBttnFifth.Image = Properties.Resources.down_button_small_lit;
        }

        private void GUIUpdateTimer_Tick(object sender, EventArgs e)
        {
            if (elevator.getDoorStatus().Equals("open"))
            {
                if (elevator.getCurrentFloor() == 1)
                {
                    floorOneDoors.Image = Properties.Resources.doors_open_small;
                }
                else if (elevator.getCurrentFloor() == 2)
                {
                    floorTwoDoors.Image = Properties.Resources.doors_open_small;
                }
                else if (elevator.getCurrentFloor() == 3)
                {
                    floorThreeDoors.Image = Properties.Resources.doors_open_small;
                }
                else if (elevator.getCurrentFloor() == 4)
                {
                    floorFourDoors.Image = Properties.Resources.doors_open_small;
                }
                else if (elevator.getCurrentFloor() == 5)
                {
                    floorFiveDoors.Image = Properties.Resources.doors_open_small;
                }
            }
            else if (elevator.getDoorStatus().Equals("closed"))
            {
                floorOneDoors.Image = Properties.Resources.doors_closed_small;
                floorTwoDoors.Image = Properties.Resources.doors_closed_small;
                floorThreeDoors.Image = Properties.Resources.doors_closed_small;
                floorFourDoors.Image = Properties.Resources.doors_closed_small;
                floorFiveDoors.Image = Properties.Resources.doors_closed_small;
            }
            if (elevator.getCurrentFloor() == 1)
            {
                firstFloorPanel.BorderStyle = BorderStyle.FixedSingle;
                secondFloorPanel.BorderStyle = BorderStyle.None;
                thirdFloorPanel.BorderStyle = BorderStyle.None;
                fourthFloorPanel.BorderStyle = BorderStyle.None;
                fifthFloorPanel.BorderStyle = BorderStyle.None;
            }
            else if (elevator.getCurrentFloor() == 2)
            {
                firstFloorPanel.BorderStyle = BorderStyle.None;
                secondFloorPanel.BorderStyle = BorderStyle.FixedSingle;
                thirdFloorPanel.BorderStyle = BorderStyle.None;
                fourthFloorPanel.BorderStyle = BorderStyle.None;
                fifthFloorPanel.BorderStyle = BorderStyle.None; 
            }
            else if (elevator.getCurrentFloor() == 3)
            {
                firstFloorPanel.BorderStyle = BorderStyle.None;
                secondFloorPanel.BorderStyle = BorderStyle.None;
                thirdFloorPanel.BorderStyle = BorderStyle.FixedSingle;
                fourthFloorPanel.BorderStyle = BorderStyle.None;
                fifthFloorPanel.BorderStyle = BorderStyle.None; 
            }
            else if (elevator.getCurrentFloor() == 4)
            {
                firstFloorPanel.BorderStyle = BorderStyle.None;
                secondFloorPanel.BorderStyle = BorderStyle.None;
                thirdFloorPanel.BorderStyle = BorderStyle.None;
                fourthFloorPanel.BorderStyle = BorderStyle.FixedSingle;
                fifthFloorPanel.BorderStyle = BorderStyle.None; 
            }
            else if (elevator.getCurrentFloor() == 5)
            {
                firstFloorPanel.BorderStyle = BorderStyle.None;
                secondFloorPanel.BorderStyle = BorderStyle.None;
                thirdFloorPanel.BorderStyle = BorderStyle.None;
                fourthFloorPanel.BorderStyle = BorderStyle.None;
                fifthFloorPanel.BorderStyle = BorderStyle.FixedSingle; 
            }
        }

        private void elevatorChecker_Tick(object sender, EventArgs e)
        {
            String command = getNextCommand();
            if (command.Equals("up1")) 
            {
                if (elevator.getCurrentFloor() == 1)
                {
                    elevator.setDoors("open");
                    elevator.setMovingDirection("waiting");
                    Thread.Sleep(500);
                    elevator.setCurrentFloor(1);
                    upBttnFirst.Image = Properties.Resources.up_button_small;
                    removeCommand("allCommands", "up1");
                    removeCommand("firstFloorCommands", "up1");
                }
                else if (elevator.getCurrentFloor() == 2)
                {
                    if (secondFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(1);
                    }
                    else if (secondFloorCommands.Contains("down2"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                        downBttnSecond.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down2");
                        removeCommand("secondFloorCommands", "down2");
                    }
                }
                else if (elevator.getCurrentFloor() == 3)
                {
                    if (thirdFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                    }
                    else if (thirdFloorCommands.Contains("down3"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                        downBttnThird.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down3");
                        removeCommand("thirdFloorsCommands", "down3");
                    }
                }
                else if (elevator.getCurrentFloor() == 4)
                {
                    if (fourthFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                    }
                    else if (fourthFloorCommands.Contains("down4"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                        downBttnFourth.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down4");
                        removeCommand("fourthFloorCommands", "down4");
                    }
                }
                else if (elevator.getCurrentFloor() == 5)
                {
                    if (fifthFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                    }
                    else if (fifthFloorCommands.Contains("down5"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(5);
                        downBttnFifth.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down5");
                        removeCommand("fifthFloorCommands", "down5");
                    }
                }
            }
            else if (command.Equals("down2"))
            {
                if (elevator.getCurrentFloor() == 1)
                {
                    if (firstFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                    }
                    else if (firstFloorCommands.Contains("up1"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(1);
                        upBttnFirst.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up1");
                        removeCommand("firstFloorCommands", "up1");
                    }
                }
                else if (elevator.getCurrentFloor() == 2)
                {
                    elevator.setDoors("open");
                    elevator.setMovingDirection("waiting");
                    Thread.Sleep(500);
                    elevator.setCurrentFloor(2);
                    downBttnSecond.Image = Properties.Resources.down_button_small;
                    removeCommand("allCommands", "down2");
                    removeCommand("secondFloorCommands", "down2");
                }
                else if (elevator.getCurrentFloor() == 3)
                {
                    if (thirdFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                    }
                    else if (thirdFloorCommands.Contains("down3"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                        downBttnThird.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down3");
                        removeCommand("thirdFloorCommands", "down3");
                    }
                }
                else if (elevator.getCurrentFloor() == 4)
                {
                    if (fourthFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                    }
                    else if (fourthFloorCommands.Contains("down4"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                        downBttnFourth.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down4");
                        removeCommand("fourthFloorCommands", "down4");
                    }
                }
                else if (elevator.getCurrentFloor() == 5)
                {
                    if (fifthFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                    }
                    else if (fifthFloorCommands.Contains("down5"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(5);
                        downBttnFifth.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down5");
                        removeCommand("fifthFloorCommands", "down5");
                    }
                }
            }
            else if (command.Equals("up2"))
            {
                if (elevator.getCurrentFloor() == 1)
                {
                    if (firstFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                    }
                    else if (firstFloorCommands.Contains("up1"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(1);
                        upBttnFirst.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up1");
                        removeCommand("firstFloorCommands", "up1");
                    }
                }
                else if (elevator.getCurrentFloor() == 2)
                {
                    elevator.setDoors("open");
                    elevator.setMovingDirection("waiting");
                    Thread.Sleep(500);
                    elevator.setCurrentFloor(2);
                    upBttnSecond.Image = Properties.Resources.up_button_small;
                    removeCommand("allCommands", "up2");
                    removeCommand("secondFloorCommands", "up2");
                }
                else if (elevator.getCurrentFloor() == 3)
                {
                    if (thirdFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                    }
                    else if (thirdFloorCommands.Contains("down3"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                        downBttnThird.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down3");
                        removeCommand("thirdFloorCommands", "down3");
                    }
                }
                else if (elevator.getCurrentFloor() == 4)
                {
                    if (fourthFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                    }
                    else if (fourthFloorCommands.Contains("down4"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                        downBttnFourth.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down4");
                        removeCommand("fourthFloorCommands", "down4");
                    }
                }
                else if (elevator.getCurrentFloor() == 5)
                {
                    if (fifthFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                    }
                    else if (fifthFloorCommands.Contains("down5"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(5);
                        downBttnFifth.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down5");
                        removeCommand("fifthFloorCommands", "down5");
                    }
                }
            }
            else if (command.Equals("down3"))
            {
                if (elevator.getCurrentFloor() == 1)
                {
                    if (firstFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                    }
                    else if (firstFloorCommands.Contains("up1"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(1);
                        upBttnFirst.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up1");
                        removeCommand("firstFloorCommands", "up1");
                    }
                    else if (elevator.getCurrentFloor() == 2)
                    {
                        if (secondFloorCommands.Count == 0)
                        {
                            elevator.setDoors("closed");
                            elevator.setMovingDirection("moving up");
                            Thread.Sleep(500);
                            elevator.setCurrentFloor(3);
                        }
                        else if (secondFloorCommands.Contains("up2"))
                        {
                            elevator.setDoors("open");
                            elevator.setMovingDirection("waiting");
                            Thread.Sleep(500);
                            elevator.setCurrentFloor(2);
                            upBttnSecond.Image = Properties.Resources.up_button_small;
                            removeCommand("allCommands", "up2");
                            removeCommand("secondFloorCommands", "up2");
                        }
                    }
                    else if (elevator.getCurrentFloor() == 3)
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                        downBttnThird.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down3");
                        removeCommand("thirdFloorCommands", "down3");
                    }
                    else if (elevator.getCurrentFloor() == 4)
                    {
                        if (fourthFloorCommands.Count == 0)
                        {
                            elevator.setDoors("closed");
                            elevator.setMovingDirection("moving down");
                            Thread.Sleep(500);
                            elevator.setCurrentFloor(3);
                        }
                        else if (fourthFloorCommands.Contains("down4"))
                        {
                            elevator.setDoors("open");
                            elevator.setMovingDirection("waiting");
                            Thread.Sleep(500);
                            elevator.setCurrentFloor(4);
                            downBttnFourth.Image = Properties.Resources.down_button_small;
                            removeCommand("allCommands", "down4");
                            removeCommand("fourthFloorCommands", "down4");
                        }
                    }
                    else if (elevator.getCurrentFloor() == 5)
                    {
                        if (fifthFloorCommands.Count == 0)
                        {
                            elevator.setDoors("closed");
                            elevator.setMovingDirection("moving down");
                            Thread.Sleep(500);
                            elevator.setCurrentFloor(4);
                        }
                        else if (fifthFloorCommands.Contains("down5"))
                        {
                            elevator.setDoors("open");
                            elevator.setMovingDirection("waiting");
                            Thread.Sleep(500);
                            elevator.setCurrentFloor(5);
                            downBttnFifth.Image = Properties.Resources.down_button_small;
                            removeCommand("allCommands", "down5");
                            removeCommand("fifthFloorCommands", "down5");
                        }
                    }
                }
            }
            else if (command.Equals("up3"))
            {
                if (elevator.getCurrentFloor() == 1)
                {
                    if (firstFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                    }
                    else if (firstFloorCommands.Contains("up1"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(1);
                        upBttnFirst.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up1");
                        removeCommand("firstFloorCommands", "up1");
                    }
                }
                else if (elevator.getCurrentFloor() == 2)
                {
                    if (secondFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                    }
                    else if (secondFloorCommands.Equals("up2"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                        upBttnSecond.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up2");
                        removeCommand("secondFloorCommands", "up2");
                    }
                }
                else if (elevator.getCurrentFloor() == 3)
                {
                    elevator.setDoors("open");
                    elevator.setMovingDirection("waiting");
                    Thread.Sleep(500);
                    elevator.setCurrentFloor(3);
                    upBttnThird.Image = Properties.Resources.up_button_small;
                    removeCommand("allCommands", "up3");
                    removeCommand("thirdFloorCommands", "up3");
                }
                else if (elevator.getCurrentFloor() == 4)
                {
                    if (fourthFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                    }
                    else if (fourthFloorCommands.Contains("down4"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                        downBttnFourth.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down4");
                        removeCommand("fourthFloorCommands", "down4");
                    }
                }
                else if (elevator.getCurrentFloor() == 5)
                {
                    if (fifthFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                    }
                    else if (fifthFloorCommands.Contains("down5"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(5);
                        downBttnFifth.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down5");
                        removeCommand("fifthFloorCommands", "down5");
                    }
                }
            }
            else if (command.Equals("down4"))
            {
                if (elevator.getCurrentFloor() == 1)
                {
                    if (firstFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                    }
                    else if (firstFloorCommands.Contains("up1"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(1);
                        upBttnFirst.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up1");
                        removeCommand("firstFloorCommands", "up1");
                    }
                }
                else if (elevator.getCurrentFloor() == 2)
                {
                    if (secondFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                    }
                    else if (secondFloorCommands.Contains("up2"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                        upBttnSecond.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up2");
                        removeCommand("secondFloorCommands", "up2");
                    }
                }
                else if (elevator.getCurrentFloor() == 3)
                {
                    if (thirdFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                    }
                    else if (thirdFloorCommands.Contains("up3"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                        upBttnThird.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up3");
                        removeCommand("thirdFloorCommands", "up3");
                    }
                }
                else if (elevator.getCurrentFloor() == 4)
                {
                    elevator.setDoors("open");
                    elevator.setMovingDirection("waiting");
                    Thread.Sleep(500);
                    elevator.setCurrentFloor(4);
                    downBttnFourth.Image = Properties.Resources.down_button_small;
                    removeCommand("allCommands", "down4");
                    removeCommand("fourthFloorCommands", "down4");
                }
                else if (elevator.getCurrentFloor() == 5)
                {
                    if (fifthFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                    }
                    else if (fifthFloorCommands.Contains("down5"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(5);
                        downBttnFifth.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down5");
                        removeCommand("fifthFloorCommands", "down5");
                    }
                }
            }
            else if (command.Equals("up4"))
            {
                if (elevator.getCurrentFloor() == 1)
                {
                    if (firstFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                    }
                    else if (firstFloorCommands.Contains("up1"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(1);
                        upBttnFirst.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up1");
                        removeCommand("firstFloorCommands", "up1");
                    }
                }
                else if (elevator.getCurrentFloor() == 2)
                {
                    if (secondFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                    }
                    else if (secondFloorCommands.Contains("up2"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                        upBttnSecond.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up2");
                        removeCommand("secondFloorCommands", "up2");
                    }
                }
                else if (elevator.getCurrentFloor() == 3)
                {
                    if (thirdFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                    }
                    else if (thirdFloorCommands.Contains("up3"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                        upBttnThird.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up3");
                        removeCommand("thirdFloorCommands", "up3");
                    }
                }
                else if (elevator.getCurrentFloor() == 4)
                {
                    elevator.setDoors("open");
                    elevator.setMovingDirection("waiting");
                    Thread.Sleep(500);
                    elevator.setCurrentFloor(4);
                    upBttnFourth.Image = Properties.Resources.up_button_small;
                    removeCommand("allCommands", "up4");
                    removeCommand("fourthFloorCommands", "up4");
                }
                else if (elevator.getCurrentFloor() == 5)
                {
                    if (fifthFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                    }
                    else if (fifthFloorCommands.Contains("down5"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(5);
                        downBttnFifth.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down5");
                        removeCommand("fifthFloorCommands", "down5");
                    }
                }
            }
            if (command.Equals("up4"))
            {
                if (elevator.getCurrentFloor() == 1)
                {
                    if (firstFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                    }
                    else if (firstFloorCommands.Contains("up1"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(1);
                        upBttnFirst.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up1");
                        removeCommand("firstFloorCommands", "up1");
                    }
                }
                else if (elevator.getCurrentFloor() == 2)
                {
                    if (secondFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                    }
                    else if (secondFloorCommands.Contains("up2"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                        upBttnSecond.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up2");
                        removeCommand("secondFloorCommands", "up2");
                    }
                }
                else if (elevator.getCurrentFloor() == 3)
                {
                    if (thirdFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                    }
                    else if (thirdFloorCommands.Contains("up3"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                        upBttnThird.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up3");
                        removeCommand("thirdFloorCommands", "up3");
                    }
                }
                else if (elevator.getCurrentFloor() == 4)
                {
                    elevator.setDoors("open");
                    elevator.setMovingDirection("waiting");
                    Thread.Sleep(500);
                    elevator.setCurrentFloor(4);
                    upBttnFourth.Image = Properties.Resources.up_button_small;
                    removeCommand("allCommands", "up4");
                    removeCommand("fourthFloorCommands", "up4");
                }
                else if (elevator.getCurrentFloor() == 5)
                {
                    if (fifthFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving down");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                    }
                    else if (fifthFloorCommands.Contains("down5"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(5);
                        downBttnFifth.Image = Properties.Resources.down_button_small;
                        removeCommand("allCommands", "down5");
                        removeCommand("fifthFloorCommands", "down5");
                    }
                }
            }
            if (command.Equals("down5"))
            {
                if (elevator.getCurrentFloor() == 1)
                {
                    if (firstFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                    }
                    else if (firstFloorCommands.Contains("up1"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(1);
                        upBttnFirst.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up1");
                        removeCommand("firstFloorCommands", "up1");
                    }
                }
                else if (elevator.getCurrentFloor() == 2)
                {
                    if (secondFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                    }
                    else if (secondFloorCommands.Contains("up2"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(2);
                        upBttnSecond.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up2");
                        removeCommand("secondFloorCommands", "up2");
                    }
                }
                else if (elevator.getCurrentFloor() == 3)
                {
                    if (thirdFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                    }
                    else if (thirdFloorCommands.Contains("up3"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(3);
                        upBttnThird.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up3");
                        removeCommand("thirdFloorCommands", "up3");
                    }
                }
                else if (elevator.getCurrentFloor() == 4)
                {
                    if (fourthFloorCommands.Count == 0)
                    {
                        elevator.setDoors("closed");
                        elevator.setMovingDirection("moving up");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(5);
                    }
                    else if (fourthFloorCommands.Contains("up4"))
                    {
                        elevator.setDoors("open");
                        elevator.setMovingDirection("waiting");
                        Thread.Sleep(500);
                        elevator.setCurrentFloor(4);
                        upBttnFourth.Image = Properties.Resources.up_button_small;
                        removeCommand("allCommands", "up4");
                        removeCommand("fourthFloorCommands", "up4");
                    }
                }
                else if (elevator.getCurrentFloor() == 5)
                {
                    elevator.setDoors("open");
                    elevator.setMovingDirection("waiting");
                    Thread.Sleep(500);
                    elevator.setCurrentFloor(5);
                    downBttnFifth.Image = Properties.Resources.down_button_small;
                    removeCommand("allCommands", "down5");
                    removeCommand("fifthFloorCommands", "down5");
                }
            }
        }
    }
}